#include "StdAfx.h"
#include "AESUtils.h"
#include <stdio.h>

/**
 *  Module Name: 	AESUtils.cpp
 *  
 *  Module defines accessor functions for AES configuration structure 
 *  used by the AES secrecy algorithm.
 *
 * 
 * @author Ravi Mohandas, Mar 06 2011
 */


	/**
	 * accessors to the AES configuration parameters
	 * 
	 */

int get_nRounds(AESConfiguration* cfg)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	return cfg->_nRoundsTransforms;
}

int get_nKeyChunks(AESConfiguration* cfg)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	return cfg->_nKeyBlks;

}

int get_nDataChunks(AESConfiguration* cfg)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	return cfg->_nDataBlks;

}


int set_nRounds(AESConfiguration* cfg, int nRounds)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	cfg->_nRoundsTransforms = nRounds;

	return E_SUCCESS;
}

int set_nKeyChunks(AESConfiguration* cfg, int nKeyBlks)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	cfg->_nKeyBlks = nKeyBlks;

	return E_SUCCESS;
}

int set_nDataChunks(AESConfiguration* cfg, int nDataBlks)
{
	if (NULL == cfg){
		perror(E_INVALID_PARAMS);
	}

	cfg->_nDataBlks = nDataBlks;

	return E_SUCCESS;
}


SecrecyLevel get_secrecyLevel (SecrecySystem* system)
{
	if (NULL == system){
		perror(E_INVALID_PARAMS);
	}

	return system->_secrecyLevel;
}

byte** get_keyRef (SecrecySystem* system)
{
	if (NULL == system){
		perror(E_INVALID_PARAMS);
	}

	return (byte **) &system->_keyRef;
}

int	get_keyLength (SecrecySystem* system)
{
	if (NULL == system){
		perror(E_INVALID_PARAMS);
	}

	return system->_keyLength;
}

int	set_secrecyLevel (SecrecySystem* system, SecrecyLevel level)
{
	if (NULL == system){
		perror(E_INVALID_PARAMS);
	}

	system->_secrecyLevel = level;

	return E_SUCCESS;
}

int set_keyRef (SecrecySystem* system, byte* key, int keyLength)
{
	if (NULL == system || NULL == key){
		perror(E_INVALID_PARAMS);
		return E_INVALID_PARAMS;
	}

	memcpy ((void *) system->_keyRef, key, sizeof(byte));
	system->_keyLength = keyLength;

	return E_SUCCESS;
}



	/**
	 * Utility routines
	 * 
	 */

void perror (int errorCode)
{
	switch (errorCode)
	{
		case E_NO_MEMORY:
			{
				printf ("System reports no memory error\n");
			}
		case E_INVALID_PARAMS:
			{
				printf ("System reports invalid parameters error\n");
			}
		case E_INVALID_STATE:
			{
				printf ("System reports invalid State error\n");
			}
		default:
			{
				printf ("System reports Error! Error code Unknown\n");
			}
	}
}



